package com.weasel.security.escape.defaults;

import com.weasel.core.helper.GodHands;
import com.weasel.security.annotation.XssEscape;
import com.weasel.security.helper.XssEscapeHelper;
import org.apache.commons.lang.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;

/**
 * Created by Dylan on 2015/12/18.
 */
public class DefaultXssEscapeService extends AbstractEscapeService {

    private final static Logger logger = LoggerFactory.getLogger(DefaultXssEscapeService.class);

    @Override
    protected <T> Field[] getEscapeFiles(T obj) {
        return GodHands.getAnnotaionFields(obj.getClass(), XssEscape.class);
    }

    @Override
    protected String escapeString(String text) {
        String _value = XssEscapeHelper.xssEscape(text);
        if(logger.isDebugEnabled()){
            logger.debug("escaper value [{}] to [{}]",text,_value);
        }
        return _value;
    }
}
